//
//  ViewController.m
//  UI09_UITabBarController
//
//  Created by LGC on 16/3/21.
//  Copyright © 2016年 Apon. All rights reserved.
//


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

#import "ViewController.h"
#import "SecondVCOfNavi.h"
@interface ViewController ()

@property (nonatomic, retain)UIButton *button;

@property (nonatomic, retain)UIButton *button1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    self.navigationItem.title = @"首页";
    [self createButton];
    [self createButton1];
    // Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 创建一个button, 用来清除对应tabBarItem的角标.
- (void)createButton {
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button.frame = CGRectMake(0, 0, 100, 100);
    self.button.center = self.view.center;
    self.button.backgroundColor = [UIColor blueColor];
    [self.button setTitle:@"点击" forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(handleRead:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button];
    
}

- (void)handleRead:(UIButton *)button {
    
    self.navigationController.tabBarItem.badgeValue = nil;
}

#pragma mark - 创建一个button, 用来推出navgation下的第二个界面.
- (void)createButton1 {
    self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button1.frame = CGRectMake(WIDTH / 4.f, 450, WIDTH / 4.f * 2, 60);
    
    self.button1.backgroundColor = [UIColor blueColor];
    [self.button1 setTitle:@"点击" forState:UIControlStateNormal];
    [self.button1 addTarget:self action:@selector(handlePush:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button1];
    
}

/** 推出第二个界面. */
- (void)handlePush:(UIButton *)button {
    SecondVCOfNavi *second = [[SecondVCOfNavi alloc]init];
    
    [self.navigationController pushViewController: second   animated:YES];
    
    [second release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
